/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.lucas.controlgasto.config;

import ar.lucas.controlgasto.login.SelectDB;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

/**
 *
 * @author lucmussi
 */
public class Propiedades {
    public static void initGeneralProper() {
        Properties proper = new Properties();
            try {
                InputStream propsFile = new FileInputStream(System.getProperty("user.dir")+"\\config\\config.properties");
                proper.load(propsFile);
                propsFile.close(); 
            } catch (FileNotFoundException ex) {
                
            } catch (IOException ioex) {
//                try {
                    JOptionPane.showConfirmDialog(null, "No existe una Base de Datos definida, ingrese su información.", "Información", JOptionPane.OK_OPTION);
                    JDialog nuevaBD = new SelectDB(null, true);
                    nuevaBD.setLocationRelativeTo(null);
                    nuevaBD.setVisible(true);
                    
                    nuevaBD.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosed(WindowEvent e){
                        
                        }
                    });
//                    File propFile = new File(System.getProperty("user.dir")+"\\config\\config.properties");
//                    propFile.getParentFile().mkdirs();
//                    OutputStream newPropFile = new FileOutputStream(propFile);
//                    proper.setProperty("direccion", "190.210.94.193");
//                    proper.setProperty("bd", "control_gasto");
//                    proper.setProperty("user", "corvus");
//                    proper.setProperty("pwd", "#000000");
//                    proper.store(newPropFile, "Archivo de Configuración");
//                    newPropFile.close();
//                } catch (FileNotFoundException ex1) {
//                    System.out.println("Todo falló");
//                }
            }
    }
}
